package com.nidu.demo.config.executor.command;

import com.alibaba.cola.dto.Response;
import com.nidu.demo.config.ability.ConfigDomainService;
import com.nidu.demo.config.gateway.ConfigGateway;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 配置删除命令执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class ConfigDeleteCmdExe {

    private final ConfigGateway gateway;
    private final ConfigDomainService domainService;

    public Response execute(Long id) {
        // 1. 校验配置是否存在
        domainService.validateConfig(id);

        // 2. 删除配置
        gateway.deleteById(id);

        return Response.buildSuccess();
    }

    public Response execute(Set<Long> ids) {
        if (ids != null && !ids.isEmpty()) {
            // 1. 校验配置是否存在
            for (Long id : ids) {
                domainService.validateConfig(id);
            }

            // 2. 批量删除配置
            gateway.deleteByIds(ids);
        }

        return Response.buildSuccess();
    }
} 